package edu.xmu.software.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class UserRedirectController extends MultiActionController {
	
	public ModelAndView login(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("login");
	}

	public ModelAndView register(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("regist");
	}
	
	public ModelAndView additem(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String keyword = request.getParameter("keyword");
		Map<String, Object> retValue = new HashMap<String, Object>();
		if (keyword != null) {
			keyword = new String(keyword.getBytes("iso-8859-1"), "utf-8");			
			retValue.put("keyword", keyword);
		}
		return new ModelAndView("new_item", retValue);
	}
	
	public ModelAndView admin(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("adminlogin");
	}
	
	public ModelAndView not_found(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("not_found");
	}
	public ModelAndView error(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("error");
	}
	
	public ModelAndView upload(HttpServletRequest request, HttpServletResponse response) throws Exception {
		return new ModelAndView("fileupload");
	}
	
	public ModelAndView logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
		request.getSession().invalidate();
		response.sendRedirect("page.do?action=index");
		return null;
	}
}
